package com.ycc.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycc.biz.common.Result;
import com.ycc.biz.entity.BizOrder;
import com.ycc.biz.service.BizOrderService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@AllArgsConstructor
public class BizOrderController {
    private final BizOrderService orderService;

    @ApiOperation("添加订单")
    @PostMapping("/add")
    public Result<Boolean> addOrder(@RequestBody BizOrder order) {
        return Result.success(orderService.save(order));
    }

    @ApiOperation("删除订单")
    @PostMapping("/delete")
    public Result<Boolean> deleteOrder(@RequestParam Long id) {
        return Result.success(orderService.removeById(id));
    }

    @ApiOperation("更新订单")
    @PostMapping("/update")
    public Result<Boolean> updateOrder(@RequestBody BizOrder order) {
        return Result.success(orderService.updateById(order));
    }

    @ApiOperation("根据ID查询订单")
    @PostMapping("/getById")
    public Result<BizOrder> getOrderById(@RequestParam Long id) {
        return Result.success(orderService.getById(id));
    }

    @ApiOperation("分页查询订单")
    @PostMapping("/page")
    public Result<Page<BizOrder>> pageOrders(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(orderService.page(new Page<>(pageNum, pageSize)));
    }
}